﻿
@{
    ViewBag.Title = "登录 - 咕嘟咕嘟";
    Layout = "~/Views/Shared/_LayoutPage.cshtml";
}
@section head{


    <link href="~/static/css/layui.css" rel="stylesheet" />
    <script src="/js/jquery-1.11.3.min.js"></script>
    <script src="~/static/layui.js"></script>

}


@section blurWrap{
    <div class="blurWrap" id="shop">
}
<!--首页banner开始-->
<div class="timeLimit">
    <h2>登录</h2>
    <hr>
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">账号</label>
            <div class="layui-input-inline">
                <input type="text" name="uname" required lay-verify="required" placeholder="可以使用账号或手机号" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-inline">
                <input type="password" name="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
            </div>

        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">免登陆</label>
            <div class="layui-input-block">
                <input type="checkbox" name="auto_login" lay-filter="auto_login" value="true" lay-skin="switch" >
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="login">立即登录</button>
                <span style="padding-left:20px;">          <a style="display:inline!important" href="/user/forget">忘记密码？</a>        </span>
            </div>
        </div>

    </form>
</div>

<script>
    var auto_login = false;
    layui.use("form", function () {
        var form = layui.form();
        form.on('submit(login)', function (data) {
            //console.log(data.elem) //被执行事件的元素DOM对象，一般为button对象
            //console.log(data.form) //被执行提交的form对象，一般在存在form标签时才会返回
            //console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
            //layer.msg(JSON.stringify(data.field));
            
            uname = data.field.uname;
            pass = data.field.password;
            $.post("/User/Login", { username: uname, password: pass, auto_login: auto_login }, function (data) {
                
                if (data.erro_code != 0) {
                    layer.msg(data.msg)
                } else {
                    location.href = "/";
                }
            },"json")
        
          
            return false;
        });


        form.on("switch(auto_login)", function (data) {
            if (data.elem.checked) {
                auto_login = true;
            } else {
                auto_login = false;
            }
        })

    })


</script>
